package com.example.config;

import com.zaxxer.hikari.HikariDataSource;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author Shanks
 * @date 2020-05-29
 */
@Getter
@Setter
@Configuration
public class ElasticJobDataSourceConfig {

    @Value("${elastic-job.datasource.driver-class-name}")
    private String driverClassName;
    @Value("${elastic-job.datasource.url}")
    private String url;
    @Value("${elastic-job.datasource.username}")
    private String username;
    @Value("${elastic-job.datasource.password}")
    private String password;

    @Bean(name = "elasticJobDataSource")
    public DataSource dataSource() {
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setJdbcUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}